﻿/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var ItemCoorRuta;
var CoorRuta = [];
var markers2 = [];

function initializeMap() {
    ItemCoorRuta = 0;
    var haightAshbury = new google.maps.LatLng(10.466606, -73.252523);
    var mapOptions = {
        zoom: 14,
        center: haightAshbury
    };

    map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);
    //alert("marcador");
    agregarRelojes();
    
}

function removeLine() {
    poly.setMap(null);
    var polyOptions = {
        strokeColor: '#000000',
        strokeOpacity: 1.0,
        strokeWeight: 2
    };
    poly = new google.maps.Polyline(polyOptions);
    poly.setMap(map);
}

function locError(error) {
    // the current position could not be located
    alert(error);
}

function setCurrentPosition(pos) {
    currentPositionMarker = new google.maps.Marker({
        map: map,
        position: new google.maps.LatLng(
            pos.coords.latitude,
            pos.coords.longitude
        ),
        title: "Current Position",
        icon: "Recursos/bus.png"
    });
    map.panTo(new google.maps.LatLng(
            pos.coords.latitude,
            pos.coords.longitude
        ));
}

function displayAndWatch(position) {
    // set current position
    setCurrentPosition(position);
    // watch position
    watchCurrentPosition();
}

function watchCurrentPosition() {
    var positionTimer = navigator.geolocation.watchPosition(
        function (position) {
            var latitude = position.coords.latitude;
            var longitude = position.coords.longitude;
            var accuracy = position.coords.accuracy;
            var capa = document.getElementById("capa");
            // var Velocidad = position.coo
            capa.innerHTML = "latitud: " + latitude + " longitud: " + longitude + "     Presicion(en metros)  :  " + accuracy;
            setMarkerPosition(currentPositionMarker,position);
        }, function error(msg) {
            alert('Please enable your GPS position future.');
        }, { maximumAge: 0, timeout: 10000, enableHighAccuracy: true });
}

function setMarkerPosition(marker, position) {
    marker.setPosition(
        new google.maps.LatLng(
            position.coords.latitude,
            position.coords.longitude)
    );
}

function initLocationProcedure() {
    initializeMap();
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(displayAndWatch, locError);
    } else {
        alert("Your browser does not support the Geolocation API");
    }
}

function agregarRelojes() {
    var despacho = new google.maps.LatLng(10.464524093693147, -73.2490935886749);
    addMarker2(despacho,"Despacho");

    var upcsabanas = new google.maps.LatLng(10.449943113207558, -73.26027303584897);
    addMarker2(upcsabanas, "UPC Sabanas");

    var terminal = new google.maps.LatLng(10.4454378527192, -73.24261337169492);
    addMarker2(terminal, "Terminal");

    var galeria = new google.maps.LatLng(10.473122541751476, -73.24366479762875);
    addMarker2(galeria, "Galeria");

    var loperena = new google.maps.LatLng(10.47375554690831, -73.24915796169125);
    addMarker2(loperena, "Loperena");

    var calle30 = new google.maps.LatLng(10.456041464772705, -73.242988880957);
    addMarker2(calle30, "Semaforo la 30");

    var cr4Cl28 = new google.maps.LatLng(10.462524788483401, -73.23028593906247);
    addMarker2(cr4Cl28, "Cr 4 con Cll 28");

    var cr17 = new google.maps.LatLng(10.471977854143676, -73.24693709262692);
    addMarker2(cr17, "Cll 17 con Cr 11");

    var cr17 = new google.maps.LatLng(10.478601947430944, -73.27820777893066);
    addMarker2(cr17, "Nevada");

}

function addMarker2(location,reloj) {
    var marker = new google.maps.Marker({
        position: location,
        map: map,
        title: reloj
    });
    markers2.push(marker);
}

